import { ref, onMounted, computed, reactive, watch } from "vue"
import { useRoute } from 'vue-router';
import *  as util from '@/amtf/utils'
export default function (cfg = {}) {
  const currentRoute = useRoute();
  console.log(`currentRoute 👉`, currentRoute)

  const a = reactive({
    当前url: "",
    插件id: "",
    组件id: "",
    是独立详情页否: false,
    当前页类型: '列表',
    待切换视图: '看板',
  })

  const api路径 = computed(() => {
    let kk = currentRoute.meta.api路径
    return kk;
  })

  const 详情页route名 = computed(() => {
    let kk = currentRoute.name.replace('/list', '/详情')
    return kk
  })

  watch(() => currentRoute, (newValue, oldValue) => {
    if (!currentRoute) {
      return "非url情况？"
    }
    let name = currentRoute.name
    const sp = name.split('/')
    a.插件id = sp[0]
    a.组件id = sp[0] + "." + sp[1]

    let url = currentRoute.path
    a.当前url = url.replace(/^\/layout/, '');

    a.是独立详情页否 = a.当前url.includes('/detail')
    if (a.当前url.includes('/detail')) {
      a.当前页类型 = '详情页'
      a.待切换视图='列表'
    } else if (a.当前url.includes('/kanban')) {
      // console.log(`是看板 a.当前url👉`,a.当前url)
      a.当前页类型 = '看板'
      a.待切换视图='列表'
    }else{
      a.当前页类型 = '列表'
      a.待切换视图='看板'
    }

  }, { immediate: true })

  // const 插组件id = computed(() => {
  //   const currentRoute = useRoute();

  // })
  return {
    currentRoute,
    a,
    api路径,
    详情页route名,
    // 当前url
  }

}






